<?php
namespace Home\Controller;

class IntegralController extends CommonController{

	public function index(){

        $where = array();
        $where['delete_status'] = '1';
        $where['type'] = '3';
        $page = I('page') ? (int)I('page') : 1;
        $this->assign('list',D('Goods')->where($where)->page($page,5)->select());
         $this->list || $this->error('');
        $this->display(IS_POST ? 'index_list' : '');
	}

	public function detail(){
        
        I('get.id') && $data = D('Goods')->where(array('id'=>(int)I('get.id'),'delete_status'=>'1','status'=>'1'))->find();
        !$data && $this->error('不存在此物品',U('index'));
        $address = D('Address')->where(array('user_id'=>$this->user['id'],'is_default'=>'5'))->find();

        if(I('get.address_id')){
            $address = D('Address')->where(array('id'=>I('get.address_id')))->find();
            session('address','');
        }
        $this->assign('address',$address);
        $this->assign('data',output_data($data));
		$this->display();
	}

    public function add(){
        D('goods')->integral($this->user['id']) || $this->error(D('goods')->getError());
        $this->success('兑换成功!',U('User/integral_info'));
    }	
}